home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kglobal.h < prev    next >
Encoding:
C/C++ Source or Header  |  2005-10-10  |  6.9 KB  |  238 lines

  1. /* This file is part of the KDE libraries
  2.    Copyright (C) 1999 Sirtaj Singh Kanq <taj@kde.org>
  3.  
  4.    This library is free software; you can redistribute it and/or
  5.    modify it under the terms of the GNU Library General Public
  6.    License version 2 as published by the Free Software Foundation.
  7.  
  8.    This library is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  11.    Library General Public License for more details.
  12.  
  13.    You should have received a copy of the GNU Library General Public License
  14.    along with this library; see the file COPYING.LIB.  If not, write to
  15.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16.    Boston, MA 02110-1301, USA.
  17. */
  18. #ifndef _KGLOBAL_H
  19. #define _KGLOBAL_H
  20.  
  21. #include "kdelibs_export.h"
  22. #include <kinstance.h> // KDE4: class KInstance is enough here
  23.  
  24. class KCharsets;
  25. class KConfig;
  26. class KSharedConfig;
  27. class KIconLoader;
  28. class KLocale;
  29. class KStandardDirs;
  30. class KStaticDeleterBase;
  31. class KStaticDeleterList;
  32. class KStringDict;
  33. class QString;
  34.  
  35. /**
  36.  * Access to the KDE global objects.
  37.  * KGlobal provides you with pointers of many central
  38.  * objects that exist only once in the process. It is also
  39.  * responsible for managing instances of KStaticDeleterBase.
  40.  *
  41.  * @see KStaticDeleterBase
  42.  * @author Sirtaj Singh Kang (taj@kde.org)
  43.  */
  44. class KDECORE_EXPORT KGlobal
  45. {
  46. public:
  47.  
  48.     /**
  49.      * Returns the global instance.  There is always at least
  50.      * one instance of a component in one application (in most
  51.      * cases the application itself).
  52.      * @return the global instance
  53.      */
  54.     static KInstance            *instance();
  55.  
  56.     /**
  57.      *  Returns the application standard dirs object.
  58.      * @return the global standard dir object
  59.      */
  60.     static KStandardDirs    *dirs();
  61.  
  62.     /**
  63.      *  Returns the general config object.
  64.      * @return the global configuration object.
  65.      */
  66.     static KConfig        *config();
  67.  
  68.     /**
  69.      *  Returns the general config object.
  70.      * @return the global configuration object.
  71.      */
  72.     static KSharedConfig        *sharedConfig();
  73.  
  74.     /**
  75.      *  Returns an iconloader object.
  76.      * @return the global iconloader object
  77.      */
  78.     static KIconLoader            *iconLoader();
  79.  
  80.     /**
  81.      * Returns the global locale object.
  82.      * @return the global locale object
  83.      */
  84.     static KLocale              *locale();
  85.  
  86.     /**
  87.      * The global charset manager.
  88.      * @return the global charset manager
  89.      */
  90.     static KCharsets            *charsets();
  91.  
  92.     /**
  93.      * Creates a static QString.
  94.      *
  95.      * To be used inside functions(!) like:
  96.      * \code
  97.      * static const QString &myString = KGlobal::staticQString("myText");
  98.      * \endcode
  99.      *
  100.      * !!! Do _NOT_ use: !!!
  101.      * \code
  102.      * static QString myString = KGlobal::staticQString("myText");
  103.      * \endcode
  104.      * This creates a static object (instead of a static reference)
  105.      * and as you know static objects are EVIL.
  106.      * @param str the string to create
  107.      * @return the static string
  108.      */
  109.     static const QString        &staticQString(const char *str);
  110.  
  111.     /**
  112.      * Creates a static QString.
  113.      *
  114.      * To be used inside functions(!) like:
  115.      * \code
  116.      * static const QString &myString = KGlobal::staticQString(i18n("My Text"));
  117.      * \endcode
  118.      *
  119.      * !!! Do _NOT_ use: !!!
  120.      * \code
  121.      * static QString myString = KGlobal::staticQString(i18n("myText"));
  122.      * \endcode
  123.      * This creates a static object (instead of a static reference)
  124.      * and as you know static objects are EVIL.
  125.      * @param str the string to create
  126.      * @return the static string
  127.      */
  128.     static const QString        &staticQString(const QString &str);
  129.  
  130.     /**
  131.      * Registers a static deleter.
  132.      * @param d the static deleter to register
  133.      * @see KStaticDeleterBase
  134.      * @see KStaticDeleter
  135.      */
  136.     static void registerStaticDeleter(KStaticDeleterBase *d);
  137.  
  138.     /**
  139.      * Unregisters a static deleter.
  140.      * @param d the static deleter to unregister
  141.      * @see KStaticDeleterBase
  142.      * @see KStaticDeleter
  143.      */
  144.     static void unregisterStaticDeleter(KStaticDeleterBase *d);
  145.  
  146.     /**
  147.      * Calls KStaticDeleterBase::destructObject() on all
  148.      * registered static deleters and unregisters them all.
  149.      * @see KStaticDeleterBase
  150.      * @see KStaticDeleter
  151.      */
  152.     static void deleteStaticDeleters();
  153.  
  154.     //private:
  155.     static  KStringDict         *_stringDict;
  156.     static  KInstance           *_instance;
  157.     static  KLocale             *_locale;
  158.     static  KCharsets            *_charsets;
  159.     static  KStaticDeleterList  *_staticDeleters;
  160.  
  161.     /**
  162.      * The instance currently active (useful in a multi-instance
  163.      * application, such as a KParts application).
  164.      * Don't use this - it's mainly for KAboutDialog and KBugReport.
  165.      * @internal
  166.      */
  167.     static void setActiveInstance(KInstance *d);
  168.     static KInstance *activeInstance() { return _activeInstance; }
  169.  
  170.     static  KInstance           *_activeInstance;
  171. };
  172.  
  173. /**
  174.  * \relates KGlobal
  175.  * A typesafe function to find the minimum of the two arguments.
  176.  */
  177. #define KMIN(a,b)    kMin(a,b)
  178. /**
  179.  * \relates KGlobal
  180.  * A typesafe function to find the maximum of the two arguments.
  181.  */
  182. #define KMAX(a,b)    kMax(a,b)
  183. /**
  184.  * \relates KGlobal
  185.  * A typesafe function to determine the absolute value of the argument.
  186.  */
  187. #define KABS(a)    kAbs(a)
  188. /**
  189.  * \relates KGlobal
  190.  * A typesafe function that returns x if it's between low and high values.
  191.  * low if x is smaller than then low and high if x is bigger than high.
  192.  */
  193. #define KCLAMP(x,low,high) kClamp(x,low,high)
  194.  
  195. // XXX KDE4: Make kMin, kMax and kClamp return "T" instead of "const T &"!
  196. template<class T>
  197. inline const T& kMin (const T& a, const T& b) { return a < b ? a : b; }
  198.  
  199. template<class T>
  200. inline const T& kMax (const T& a, const T& b) { return b < a ? a : b; }
  201.  
  202. template<class T>
  203. inline T kAbs (const T& a) { return a < 0 ? -a : a; }
  204.  
  205. template<class T>
  206. inline const T& kClamp( const T& x, const T& low, const T& high )
  207. {
  208.     if ( x < low )       return low;
  209.     else if ( high < x ) return high;
  210.     else                 return x;
  211. }
  212.  
  213. /**
  214.  * Locale-independent qstricmp. Use this for comparing ascii keywords
  215.  * in a case-insensitive way.
  216.  * qstricmp fails with e.g. the Turkish locale where 'I'.lower() != 'i'
  217.  * @since 3.4
  218.  */
  219. int KDECORE_EXPORT kasciistricmp( const char *str1, const char *str2 );
  220.  
  221.  
  222. /**
  223.  * \mainpage The KDE Core Functionality Library
  224.  *
  225.  * All KDE programs use this library to provide basic functionality such
  226.  * as the configuration system, IPC, internationalization and locale
  227.  * support, site-independent access to the filesystem and a large number
  228.  * of other (but no less important) things.
  229.  *
  230.  * All KDE applications should link to the kdecore library. Also, using a
  231.  * KApplication derived class instead of QApplication is almost
  232.  * mandatory if you expect your application to behave nicely within the
  233.  * KDE environment.
  234.  */
  235.  
  236. #endif // _KGLOBAL_H
  237.  
  238.